#include <stdio.h>
#include <string.h>


int main()
{
	int ret = 0;
	FILE *file;
	char buffer[256];
	int roadLength = 0;
	int lineRoad = 0;
	uint32_t solution = 0;	
	char rightVal[5] = {1, 3, 5, 7, 1};
	
	printf("Day 3 - part 2! \n");
	
	for (int i = 0; i < sizeof(rightVal) ; i++)
	{
		uint32_t noTree = 0, tree = 0;
		int moving = 0, error = 0;
		int roadCount = 0;
		
		file = fopen("input.txt", "r");
		if (file == NULL)
			return -1;
		fscanf(file, "%s", buffer);
		roadLength = strlen(buffer);

		while(!feof(file) )
		{
			roadCount++;
			fscanf(file, "%s", buffer);
			//printf("roadCount: %d - i: %d - rightVal: %d\n", roadCount, i, rightVal[i]);
			if ((roadCount % 2 == 1) && (i == sizeof(rightVal)-1))
				continue;
			else
			{
				moving += rightVal[i];
				//printf("%s ", buffer);
				//printf("buffer char : %c ", buffer[moving %roadLength]);

				if (buffer[moving%roadLength] == '.')
					noTree++;
				else if (buffer[moving %roadLength] == '#')
					tree++;
				else
					error++;	
				//printf("noTree: %u - Tree: %u\n", noTree, tree);
			}

		}

		if (solution == 0)
			solution = tree;
		else 
			solution *= tree;
		printf ("Solution: %u - tree: %u\n", solution, tree);
		fclose(file);
	}
	printf ("Final: hit %u \n", solution);
	fclose(file);


	return ret;
}


